<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .list {
            display: flex;
            justify-content: space-evenly;
            flex-wrap: wrap;
        }

        .list .item {
            width: 200px;
            border: 2px solid black;
            margin-bottom: 20px;
        }

        img {
            width: 100%;
        }
    </style>
</head>

<body>
    <input type="text">
    <button>点击搜索</button>
    <div class="list"></div>
</body>

</html>
<script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<script>
    var Ipt = document.querySelector("input")
    var Btn = document.querySelector("button")
    var Div = document.querySelector(".list")
    let debounceSearch = _.debounce(function(){},500)
    Ipt.oninput = function(){debounceSearch()}
    Btn.onclick = function () {
        let xhr = new XMLHttpRequest()
        let productAPI = "http://localhost:8888/goods/list?search=" + Ipt.value
        xhr.open('GET', productAPI)
        xhr.send()
        xhr.onload = function () {
            if (xhr.status == 200) {
                // console.log(xhr.responseText);
                let obj = JSON.parse(xhr.responseText)
                // console.log(obj);
                let str = ''
                obj.data.forEach(v => {
                    str += `<div class='item'>
                    <img src='${v.img_big_logo}'>
                    <div>${v.title}</div>
                    <div>${v.price}</div>
                    </div>`
                })
                Div.innerHTML = str
            }
        }
    }

</script>